﻿@{
    ViewBag.Title = "添加巡检区域";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var ParentId = "";
    var PStructId = "";
    var pcode = request('pcode');
    var type = request('type');
    var sp = 0;
    $(function () {
        initControl();
    })
    //初始化控件
    var ptype = "";

    function initControl() {
        //上级房产
        $("#PStructID").ComboBoxTree({
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=6",
            description: "==请选择==",
            height: "250px",
            click: function (item) {
                ptype = item.Type;
                if (ptype == "4") {
                    ParentId = item.id;
                } else {
                    dialogMsg('只能选到楼层不可以选择其他层次！', 0);
                }
            }
        });
        $("#PStructID").ComboBoxTreeSetValue(ParentId);
        //标识方式选择
        $("#Flag .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#Flag .dropdown-text").html(text).attr('data-value', value);
            switch (value) {
                case "0": $("#logo").attr("hidden", "hidden"); $(".TypeImg").attr("hidden", "hidden"); $("#FlagNo").val(""); $("#ewm").html(""); break;
                case "1": $("#logo").removeAttr("hidden"); $(".TypeImg").attr("hidden", "hidden"); $("#FlagNo").attr("type", "text").val(""); $("#ewm").html(""); break;
                case "2":
                case "3": $("#logo").removeAttr("hidden"); $(".TypeImg").removeAttr("hidden"); $("#FlagNo").val(""); $("#ewm").html(""); break;
                case "4": $("#logo").attr("hidden", "hidden"); $(".TypeImg").attr("hidden", "hidden"); $("#FlagNo").val(""); $("#ewm").html(""); break;
                default: break;
            }
        });

        //下载巡检项
        $("#PollingItem").ComboBoxTree({
            description: "==请选择==",
            height: "200px"
        });

        //获取表单
        if (!!keyValue) {
            ptype = "4";
            $.SetForm({
                url: "../../ResourceManage/RS_PublicArea/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    ParentId = data.ParentId;
                    PStructId = data.PStructID;
                    $("#form1").SetWebControls(data);

                    $("#PStructID").ComboBoxTreeSetValue(data.ParentId);
                    var value = "";
                    if (!!data.FlagWay) {
                        switch (data.FlagWay) {
                            case 0: value = "无标识"; $("#logo").attr("hidden", "hidden"); $(".TypeImg").attr("hidden", "hidden"); break;
                            case 1: value = "rfid芯片"; $("#logo").removeAttr("hidden"); $(".TypeImg").attr("hidden", "hidden"); $("#FlagNo").attr("readonly", "readonly").val(data.FlagNo); break;
                            case 2: value = "条码"; $("#logo").removeAttr("hidden"); $(".TypeImg").removeAttr("hidden"); $("#FlagNo").attr("readonly", "readonly").val(data.FlagNo); break;
                            case 3: value = "二维码"; $("#logo").removeAttr("hidden"); $(".TypeImg").removeAttr("hidden"); $("#FlagNo").attr("readonly", "readonly").val(data.FlagNo); break;
                            case 4: value = "beacon"; $("#logo").attr("hidden", "hidden"); $(".TypeImg").attr("hidden", "hidden"); break;
                        }
                        $("#Flag .dropdown-text").html(value).attr('data-value', data.FlagWay);
                    }
                    else { $("#Flag").parent().attr("hidden", "hidden").prev().attr("hidden", "hidden"); }
                    ////条形码
                    if (data.FlagWay == "2" && !!data.FlagNo) {
                        $.ajax({
                            type: "GET",
                            url: "../../ResourceManage/RS_PublicArea/GetBaCode?guid=" + $("#FlagNo").val(),
                            success: function (data) {
                                var arr = data.split(",");
                                $("#ewm").html("<img style='height:100px;width:100px;' src='../../Files/QRCode/" + arr[1] + "' />");
                            }
                        })
                    }
                    else if (data.FlagWay == "3" && !!data.FlagNo) {
                        $.ajax({
                            type: "GET",
                            url: "../../ResourceManage/RS_PublicArea/GetDimensionalCode?guid=" + $("#FlagNo").val(),
                            success: function (data) {
                                var arr = data.split(",");
                                $("#ewm").html("<img style='height:100px;width:100px;' src='../../Files/QRCode/" + arr[1] + "' />");
                            }
                        })
                    }
                    else { $(".TypeImg").attr("hidden", "hidden"); }
                    $("#shth").html("是否审核");
                    $("#shtd").html("<input type='checkbox' id='AuditMark'  />");
                    if (data.AuditMark == 1) {
                        $("#Name").attr({ "ReadOnly": "true" });
                        $("#EnCode").attr({ "ReadOnly": "true" });
                        $("#PStructID").attr({ "disabled": "true" });
                        $("#AuditMark").attr({ "disabled": "true" });
                        $("#Memo").attr({ "ReadOnly": "true" });
                        $("#Flag").attr({ "ReadOnly": "true" });
                        $("#Flag .dropdown-text").attr({ "ReadOnly": "true" });
                        $("#Flag").attr({ "disabled": "true" });
                        $("#Flag .dropdown-text").attr({ "disabled": "true" });
                        $("#Flag  a").attr({ "disabled": "true" });
                        sp = 1;
                    }
                    $("#Flag .dropdown-text").attr({ "disabled": "true" });
                    $("#Flag  a").attr({ "disabled": "true" });
                }
            });

        }
        else { $("#Flag").parent().attr("hidden", "hidden").prev().attr("hidden", "hidden"); }
    }


    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform() || ptype != "4") {
            dialogMsg('输入的数据不符合规范！', 0);
            return false;
        }
        //if (!$("#Flag .dropdown-text").attr("data-value")) {
        //    dialogMsg('请选择标识方式！', 0);
        //    return;
        //}
        var postData = $("#form1").GetWebControls(keyValue);
        postData["ParentId"] = ParentId;
        postData["PStructID"] = PStructId;
        postData["FlagWay"] = $("#Flag .dropdown-text").attr("data-value");
        if ($("#AuditMark").is(':checked')) {
            postData["AuditMark"] = 1;
            dialogConfirm('注：数据审核后将无法进行修改！', function (r) {
                if (r) {
                    $.SaveForm({
                        url: "../../ResourceManage/RS_PublicArea/SaveForm?keyValue=" + keyValue,
                        param: postData,
                        loading: "正在保存数据...",
                        success: function () {
                            $.currentIframe().$("#gridTable").trigger("reloadGrid");

                        }
                    })
                }
            });
        }
        else {
            postData["AuditMark"] = 0;
            $.SaveForm({
                url: "../../ResourceManage/RS_PublicArea/SaveForm?keyValue=" + keyValue,
                param: postData,
                loading: "正在保存数据...",
                success: function () {
                    $.currentIframe().$("#gridTable").trigger("reloadGrid");
                }
            })
        }
    }

    //生产二维码
    function creatqr() {
        var postData = $("#form1").GetWebControls(keyValue);
        var flag = $("#Flag .dropdown-text").text();

        if (flag == "二维码") {
            $.ajax({
                type: "GET",
                url: "../../ResourceManage/RS_PublicArea/GetDimensionalCode?guid=" + $("#PCode").val(),
                success: function (data) {
                    var arr = data.split(",");
                    $("#ewm").html("<img style='height:100px;width:100px;' src='../../Files/QRCode/" + arr[1] + "' />");
                    $("#FlagNo").val(arr[0]);
                }

            })
        }
        else if (flag == "条码") {
            $.ajax({
                type: "GET",
                url: "../../ResourceManage/RS_PublicArea/GetBaCode?guid=" + $("#PCode").val(),
                success: function (data) {
                    var arr = data.split(",");
                    $("#ewm").html("<img style='height:100px;width:100px;' src='../../Files/QRCode/" + arr[1] + "' />");
                    $("#FlagNo").val(arr[0]);
                }

            })
        }


    }

</script>

<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">名称<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="Name" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <th class="formTitle">编码<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="EnCode" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                <input id="PCode" type="hidden" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" id="tag">房产区域<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="PStructID" type="select" class="ui-select"></div>
            </td>

            <th class="formTitle">标识方式<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="Flag" class="btn-group" style="width:100%">
                    <a class="btn btn-default dropdown-text" data-toggle="dropdown" style="width:88%" >选择标识方式</a>
                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="width:88%">
                        <li><a data-value="0">无标识</a></li>
                        <li><a data-value="1">rfid芯片</a></li>
                        <li><a data-value="2">条码</a></li>
                        <li><a data-value="3">二维码</a></li>
                        <li><a data-value="4">beacon</a></li>
                    </ul>
                </div>
            </td>
        </tr>
        <tr id="logo" hidden="hidden">
            <th class="formTitle">标识编码</th>
            <td class="formValue" id="autocreate">
                <input type="text" id="FlagNo" class="form-control" />
                @*<input type="button" class="TypeImg" onclick="creatqr()" value="自动生成" />*@
            </td>
            <th class="formTitle"></th>
            <td class="formValue"></td>
        </tr>
        <tr style="height:90px;" class="TypeImg" hidden="hidden">
            <th class="formTitle"></th>
            <td id="ewm" colspan="3"></td>
        </tr>
        <tr class="TypeImg" hidden="hidden">
            <td colspan="3">
                <img id="FlagNoImg" />
            </td>
            <td>
                <input type="button" style="display:none;" value="打印" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" style="padding-top: 4px;">
                位置描述
            </th>
            <td class="formValue" colspan="3">
                <input type="text" class="form-control" id="OtherCode">
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">
                备注
            </th>
            <td class="formValue" colspan="3">
                <textarea id="Memo" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
        <tr>
            <th class="formTitle" id="shth"></th>
            <td class="formValue" id="shtd"></td>
        </tr>
    </table>
</div>